const { getConfig } = require("../utils/getAndSetConfig");
const {
  confirmTheGame,
  giveALike,
  lookingForGame,
  oneMoreGame,
  getLolBlueEssence,
} = require("../axios/api");

let getValue = (key) => {
  switch (key) {
    // 默认为真
    // 接受对局
    case "confirmTheGameState":
      return getConfig(key) === false ? false : true;

    // 随机点赞
    case "giveALikeState":
      return getConfig(key) === false ? false : true;
  }

  return getConfig(key) === true ? true : false;
};

setInterval(async () => {
  let data = await getLolBlueEssence();
  // 游戏是否启动
  if (data) {
    // 接受对局
    if (getValue("confirmTheGameState")) {
      await confirmTheGame();
    }
    // 随机点赞
    if (getValue("giveALikeState")) {
      await giveALike();
    }
    // 寻找对局
    if (getValue("lookingForGameState")) {
      await lookingForGame();
    }
    // 再来一局
    if (getValue("oneMoreGameState")) {
      await oneMoreGame();
    }
  }
}, 500);
